package com.yswy.app.controller;

import com.yswy.app.service.UserThirdPartyAccountService;
import com.yswy.common.model.ResultModel;
import com.yswy.common.utils.UserLockUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import static com.yswy.domain.common.util.TokenUtils.getUserId;

@RestController
@RequestMapping("/log")
@Api(description = "记录")

public class UserThirdPartyAccountController {
    @Autowired
    private UserThirdPartyAccountService userThirdPartyAccountService;

    @GetMapping("/accountFind")
    @ApiOperation(value = "提现绑定列表")
    public ResultModel accountFind(HttpServletRequest request) {
        return ResultModel.ok(userThirdPartyAccountService.accountFind(null ,getUserId(request)));
    }


    @GetMapping("/bindZfb")
    @ApiOperation(value = "绑定支付宝")
    public ResultModel bindZfb(  @RequestParam(value = "account" ) String account ,
                                            @RequestParam(value = "realName") String realName ,
                                            HttpServletRequest request) {
        synchronized (UserLockUtils.getLock("bindZfb:"+account)){
            userThirdPartyAccountService.bindZfb(account ,realName , getUserId(request));
            return ResultModel.ok();
        }

    }


}
